{include file="admin/head" /}

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">预约管理</a>
        <a>
          <cite>器具进行预约情况</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div style="padding: 20px">
    <table class="layui-table">
        <thead>
        <tr>
            <th>预约人</th>
            <th>器具名称</th>
            <th>开始时间</th>
            <th>时长</th>
            <th>所属课室</th>
            <th>管理教师</th>
            <th>提交时间</th>
            <th>状态</th>
            <th>操作</th>
        </thead>
        <tbody>
        {volist name="tools" id="tool" empty="暂无预约数据"}
        <tr>
            <td>{$tool->user->userinfo->realname|default="暂无此人信息"}</td>
            <td>{$tool->tool->name|default="暂无器具信息"}</td>
            <td>{$tool.starttime}</td>
            <td>{$tool.time}天</td>
            <td>{$tool->tool->lab->name|default="暂无实验室信息"}</td>
            <td>{$tool->tool->lab->teacher->realname|default="暂无此人信息"}</td>
            <td>
                {$tool.create_time}
            </td>
            <td class="td-status">
                {switch $tool.statu}
                {case 0}未审批 {/case}
                {case 1}借出中，尚未归还 {/case}
                {/switch}
            </td>
            <td class="td-manage">
                {switch $tool.statu}
                {case 0}
                <a class="layui-btn layui-btn-normal layui-btn-sm" title="同意"  onclick="agree(this,'{$tool.id}')" href="javascript:;">
                    同意
                </a>
                <a class="layui-btn layui-btn-primary layui-btn-sm" title="不同意" onclick=" disagree(this,'{$tool.id}')" href="javascript:;">
                    不同意
                </a>
                {/case}
                {case 1}
                <a class="layui-btn layui-btn-sm" title="确认归还"  onclick="tuihui(this,'{$tool.id}')" href="javascript:;">
                    确认归还
                </a>
                {/case}
                {/switch}

            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    <div class="page">
        {$tools|raw}
    </div>
</div>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });
        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
    });
    /*不同意*/
    function disagree(obj,id){
        layer.confirm('确认要拒绝吗？',function(index){
            //发异步删除数据
            layer.prompt({title: '退回理由', formType: 2}, function(text, index){
                $.post(
                    "{:url('tool_shenhe')}",
                    {id:id,
                        statu:2,
                        reason:text
                    },
                    function(data){
                        if (data.statu==200) {
                            $(obj).parents("tr").remove();
                            layer.msg(data.msg,{icon:1,time:1000});
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        }else{
                            layer.msg(data.msg,{icon:2,time:1000});
                        }
                    }
                )
            });
        });
    }
    function agree(obj,id) {
        $.post(
            "{:url('tool_shenhe')}",
            {
                id:id,
                statu:1,
            },
            function(data){
                if (data.statu==200) {
                    $(obj).parents("tr").find(".td-status").html('借出中,尚未归还');
                    layer.msg(data.msg,{icon:1,time:1000},function(){
                        window.location.reload();
                    });
                }else{
                    layer.msg(data.msg,{icon:2,time:1000});
                }
            }
        )
    }
    function tuihui(obj,id) {
        $.post(
            "{:url('tool_shenhe')}",
            {
                id:id,
                statu:3
            },
            function (data) {
                if (data.statu==200) {
                    $(obj).parents("tr").remove();
                    layer.msg(data.msg,{icon:1,time:1000});
                }else{
                    layer.msg(data.msg,{icon:2,time:1000});
                }
            }
        )
    }
</script>
</body>
</html>